import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { MovieListService } from './movieList.service';

@Controller('/movie/list')
export class MovieListController {
    constructor(
        private readonly movieListService: MovieListService,
    ) {}

    @Post()
    getMovieList(@Body() body) {
        // todo: 分页和查询
        const { type } = body;
        if(!type) {
            throw new Error('type参数错误');
        }
        return this.movieListService.getMovieList(body);
    }
    @Get('/detail/:id')
    getMovieDetail(@Param('id') id: number) { // 把id转成数字类型
        let numberId = Number(id);
        if(isNaN(numberId)) {
            throw new Error('id参数错误');
        }
        return this.movieListService.getMovieDetail(numberId);
    }

    @Get('/download/:id')
    downloadMovie(@Param('id') id: number) {
        let numberId = Number(id);
        if(isNaN(numberId)) {
            throw new Error('id参数错误');
        }
        return this.movieListService.downloadMovie(numberId);
    }
}
